package com.yanfan.parking.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.parking.domain.IbmsParkingPlace;
import com.yanfan.parking.service.IIbmsParkingPlaceService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 车场信息Controller
 *
 * @author lzb
 * @date 2024-08-09
 */
@Api(tags = "车场信息")
@RestController
@RequestMapping("/parking/parkingLot")
public class IbmsParkingPlaceController extends BaseController {
    @Autowired
    private IIbmsParkingPlaceService ibmsParkingLotService;

    /**
     * 查询车场信息列表
     */
    @ApiOperation("车场信息分页列表")
    @PreAuthorize("@ss.hasPermi('parking:parkingLot:list')")
    @GetMapping("/list")
    public TableDataInfo list(IbmsParkingPlace ibmsParkingPlace) {
        startPage();
        List<IbmsParkingPlace> list = ibmsParkingLotService.selectIbmsParkingPlaceList(ibmsParkingPlace);
        return getDataTable(list);
    }

    /**
     * 导出车场信息列表
     */
    @ApiOperation("导出车场信息列表")
    @PreAuthorize("@ss.hasPermi('parking:parkingLot:export')")
    @Log(title = "车场信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IbmsParkingPlace ibmsParkingPlace) {
        List<IbmsParkingPlace> list = ibmsParkingLotService.selectIbmsParkingPlaceList(ibmsParkingPlace);
        ExcelUtil<IbmsParkingPlace> util = new ExcelUtil<IbmsParkingPlace>(IbmsParkingPlace.class);
        util.exportExcel(response, list, "车场信息数据");
    }

    /**
     * 获取车场信息详细信息
     */
    @ApiOperation("获取车场信息详细信息")
    @PreAuthorize("@ss.hasPermi('parking:parkingLot:query')")
    @GetMapping(value = "/{parkingLotId}")
    public AjaxResult getInfo(@PathVariable("parkingLotId") Long parkingLotId) {
        return success(ibmsParkingLotService.getById(parkingLotId));
    }

    /**
     * 新增车场信息
     */
    @ApiOperation("新增车场信息")
    @PreAuthorize("@ss.hasPermi('parking:parkingLot:add')")
    @Log(title = "车场信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IbmsParkingPlace ibmsParkingPlace) {
        return toAjax(ibmsParkingLotService.save(ibmsParkingPlace));
    }

    /**
     * 修改车场信息
     */
    @ApiOperation("修改车场信息")
    @PreAuthorize("@ss.hasPermi('parking:parkingLot:edit')")
    @Log(title = "车场信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IbmsParkingPlace ibmsParkingPlace) {
        return toAjax(ibmsParkingLotService.updateById(ibmsParkingPlace));
    }

    /**
     * 删除车场信息
     */
    @ApiOperation("删除车场信息")
    @PreAuthorize("@ss.hasPermi('parking:parkingLot:remove')")
    @Log(title = "车场信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{parkingLotIds}")
    public AjaxResult remove(@PathVariable Long[] parkingLotIds) {
        return toAjax(ibmsParkingLotService.removeBatchByIds(Arrays.asList(parkingLotIds)));
    }
}
